<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">餐桌列表</div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom am-cf">
                        <form class="toolbar-form">
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-form-group">
                                    <div class="am-btn-group am-btn-group-sm">
                                        <a href="javascript:void(0);" class="hema-add am-btn am-btn-primary am-radius">
                                            <span class="am-icon-plus"></span> 添加
                                        </a>
                                    </div>
                                </div>
                            </div>
                         
                        </form>
                    </div>
                    <div class="am-scrollable-horizontal am-u-sm-12">
                        <table width="100%" class="am-table am-table-hover tpl-table-black">
                            <thead>
                            <tr>
                                <th>编号ID</th>
                                <th>餐桌名称</th>
                                <th>自定编号</th>
                                <th>餐桌码</th>
                                <th>餐桌状态</th>
                                <th>显示排序</th>
                                <th>添加时间</th>
                                <th>管理操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {if sizeof($list)>0}
                                {foreach $list as $index => $item}
                                <tr>
                                    <td class="am-text-middle">{$item['table_id']}</td>
                                    <td class="am-text-middle">
                                        <p class="item-title">{$item['table_name']}</p>
                                    </td>
                                    <td class="am-text-middle">{$item['row_no']}</td>
                                    <td class="am-text-middle">
                                        <a class="hema-qrcode" data-index="{$index}" href="javascript:;">
                                        <i class="iconfont iconerweima" style="font-size:25px;color:#2979ff;"></i>
                                        </a>
                                    </td>
                                    <td class="am-text-middle">
                                        <span class="am-badge {$item['status']['value'] == 10 ? ' am-badge-success' : 'am-badge-warning'}">
                                        {$item['status']['text']}
                                        </span>
                                    </td>
									<td class="am-text-middle">{$item['sort']}</td>
                                    <td class="am-text-middle">{$item['create_time']}</td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="javascript:;" class="hema-edit" data-id="{$item['table_id']}">
                                                <i class="am-icon-pencil"></i> 编辑
                                            </a>
                                            <a href="javascript:;" class="hema-del tpl-table-black-operation-del"
                                               data-id="{$item['table_id']}">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {/foreach}
                            {else /}
                                <tr>
                                    <td colspan="8" class="am-text-center">暂无记录</td>
                                </tr>
                            {/if}
                            </tbody>
                        </table>
                    </div>
					<div class="am-u-lg-12 am-cf">
					    <div class="am-fr">{:$list->render()} </div>
					    <div class="am-fr pagination-total am-margin-right">
					        <div class="am-vertical-align-middle">总记录：{:$list->total()}</div>
					    </div>
					</div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="shop/table/add" /}
{include file="shop/table/edit" /}
{include file="layout/qrcode" /}
<script>
    $(function () {
        let list = <?= json_encode($list) ?>;
        $('.hema-qrcode').click(function () {
            let data = $(this).data();
            $.showAction({
                    title: '餐桌码', 
                    area: '510px', 
                    content: template('tpl-qrcode', {qrcode:list.data[data.index].qrcode}), 
                    uCheck: true, 
                    btn: ['取消'],
                    success: function ($content) {
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
                });
        });
         //添加
        $('.hema-add').on('click', function () {
            $.showAction({
                title: '添加', 
                area: '750px', 
                content: template('tpl-add', {}), 
                uCheck: true, 
                success: function ($content) {
                    $('#my-form').formPost({
                        url: "{:url('shop.table/add')}"
                    });
                }, 
                btn2: function ($content) {
                    return true;
                }
            });
        });
        //编辑
        $('.hema-edit').on('click', function () {
            var data = $(this).data();
            $.get("{:url('shop.table/edit')}?id=" + data.id, function (result) {
				if(result.code == 0){
				    $.show_error(result.msg);
				    return false;
				}
				$.showAction({
                    title: '编辑', 
                    area: '750px', 
                    content: template('tpl-edit', {model:result.data.model}), 
                    uCheck: true, 
                    success: function ($content) {
                        $('#my-form').formPost({
                            url: "{:url('shop.table/edit')}?id=" + data.id
                        });
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
                });
            });
        });
        // 删除元素
        var url = "{:url('shop.table/delete')}";
        $('.hema-del').del('id', url);

    });
</script>

